# Streamlit Image-Comparison Component Example
# Usage: compare different images
# $ streamlit run compare_results.py


import streamlit as st
# from streamlit_image_comparison import image_comparison
import numpy as np
# set page config
st.set_page_config(page_title="Image-Comparison Example", layout="wide")
import cv2
import os



# first, we choose root dir
current_exp_root = "day14"
# st.button(current_exp_root, key=None, help=None, on_click=None, args=None, kwargs=None)
# print("choose root dir:", current_exp_root)

# exps 
# name1 = st.selectbox('name1',sorted(os.listdir(os.path.join("results/Sep",current_exp_root))))
# st.write('You selected:', name1)

# name2 = st.selectbox('name2',sorted(os.listdir(os.path.join("results/Sep",current_exp_root))))
# st.write('You selected:', name2)



index = 0
num_images = len(os.listdir("results/Sep/day14/distanceSDFNGP_mean_64_fine_128_train_free_dp1/test_all"))//2
age = st.slider('which IMAGE want to compare?', 0, num_images, 0)
st.write("current compare is on", age)

names = sorted(os.listdir(os.path.join("results/Sep",current_exp_root)))


names = ["DSNGP_mean_64_fine_128_train_free", "RawNGP_mean_64_fine_128_train_free", "distanceSDFNGP_mean_64_fine_128_train_free_dp05",
    "distanceSDFNGP_mean_64_fine_128_train_free_dp1", "info00001_distance01_SDFNGP_mean_64_fine_128"]

# is_enable = default value

for name in names:
    pass
    # Generate checkbox
    # checkbox id = name
    # is_enable[name] = st.checkbok(name, is_enable[name])

# num_class = sum([v for v in is_enable.values() if v == True])

num_class = len(names)
cols = st.columns(num_class+1)

images = []

for i in names:
    image1 = cv2.cvtColor(cv2.imread(f"results/Sep/{current_exp_root}/{i}/test_all/ngp_0047_{age:04d}.png"), cv2.COLOR_BGR2RGB)
    image1d = cv2.cvtColor(cv2.imread(f"results/Sep/{current_exp_root}/{i}/test_all/ngp_0047_{age:04d}_depth.png"), cv2.COLOR_BGR2RGB)
    image1 = np.vstack((image1, image1d)) # 1600,1600
    images.append(image1)

cols[0].image(images[0][:,:800], caption="GT",width=None, use_column_width='always', clamp=False, channels='RGB', output_format='auto')

for idx, image in enumerate(images):
    cols[idx+1].image(image[:,800:], caption=names[idx], width=None, use_column_width='always', clamp=False, channels='RGB', output_format='auto')
    # st.image(image, caption=names[idx], width=800, use_column_width=False, clamp=False, channels='RGB')



# render image-comparison
# image_comparison(
#     img1=image1,
#     img2=image2,
#     label1=name1,
#     label2=name2,
#     width=800,
# )


# # image path
# image = "image.jpg"

# # image url
# image = "https://some-url.com/image.jpg"

# # pil image
# from PIL import Image
# image = Image.open("image.jpg")

# # opencv image
# import cv2
# image = cv2.cvtColor(cv2.imread("image.jpg"), cv2.COLOR_BGR2RGB)

# # render image-comparison
# image_comparison(
#     img1=image,
#     img2=image,
# )

# image_comparison(
#     img1="image1.jpg",
#     img2="image2.jpg",
#     label1="text1",
#     label2="text1",
#     width=700,
#     starting_position=50,
#     show_labels=True,
#     make_responsive=True,
#     in_memory=True,
# )